"""Definition of the organization content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import folder
from Products.ATContentTypes.content import schemata

from Products.plonecrm import plonecrmMessageFactory as _
from Products.plonecrm.interfaces import Iorganization
from Products.plonecrm.config import PROJECTNAME

organizationSchema = folder.ATFolderSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-

    atapi.StringField(
        'newfield',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"register capital"),
            description=_(u"register capital"),
        ),
    ),


    atapi.StringField(
        'fax',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"fax number"),
            description=_(u"fax number"),
        ),
    ),


    atapi.StringField(
        'website',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"website"),
            description=_(u"the website of organization"),
        ),
    ),


    atapi.StringField(
        'postcode',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"New Field"),
            description=_(u"post code"),
        ),
    ),


    atapi.StringField(
        'business',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"main business"),
            description=_(u"this organization provided main business"),
        ),
    ),


    atapi.StringField(
        'type',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"organization type"),
            description=_(u"this organization's type"),
        ),
    ),


    atapi.StringField(
        'account',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"bank account"),
            description=_(u"bank account"),
        ),
    ),


    atapi.StringField(
        'master',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"organization legal person"),
            description=_(u"organization legal person or board chairman"),
        ),
    ),


    atapi.StringField(
        'name',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"organization name"),
            description=_(u"this organization legal regeistered name"),
        ),
        required=True,
    ),


))

# Set storage on fields copied from ATFolderSchema, making sure
# they work well with the python bridge properties.

organizationSchema['title'].storage = atapi.AnnotationStorage()
organizationSchema['description'].storage = atapi.AnnotationStorage()

schemata.finalizeATCTSchema(
    organizationSchema,
    folderish=True,
    moveDiscussion=False
)


class organization(folder.ATFolder):
    """an organization unite"""
    implements(Iorganization)

    meta_type = "organization"
    schema = organizationSchema

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-
    newfield = atapi.ATFieldProperty('newfield')

    fax = atapi.ATFieldProperty('fax')

    website = atapi.ATFieldProperty('website')

    postcode = atapi.ATFieldProperty('postcode')

    business = atapi.ATFieldProperty('business')

    type = atapi.ATFieldProperty('type')

    account = atapi.ATFieldProperty('account')

    master = atapi.ATFieldProperty('master')

    name = atapi.ATFieldProperty('name')


atapi.registerType(organization, PROJECTNAME)
